
<template>
  <page-header-wrapper :title="false">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="12">
            <a-col :span="8">
              <a-form-item label="联系电话">
                <a-input v-model="queryParam.contactNumber" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="计酬方式">
                <a-select v-model="queryParam.taskUnit" placeholder="请选择" default-value="">
                  <a-select-option value="0">天</a-select-option>
                  <a-select-option value="1">次</a-select-option>
                  <a-select-option value="2">月</a-select-option>
                  <a-select-option value="3">年</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="8" style="text-align: right;">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" style="margin-right: 8px" @click="handleSearch">查询</a-button>
                <a-button style="margin-right: 8px" @click="handleReset">重置</a-button>
                <a-button type="primary" @click="handleExport">导出</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        :scroll="{x: true}"
        :columns="columns"
        :data="loadData"
        :pageNum="pageNum"
        :pageSize="pageSize"
        rowKey="id">
        <div slot="action" slot-scope="text, record">
          <a type="primary" :disabled="record.state === 1" @click="handleStatus(record)">激活</a>
          <a
            :disabled="record.state === 2"
            @click="handleStatus(record)"
            style="margin-left:10px;">冻结</a>
        </div>
      </s-table>
    </a-card>
    <!-- <create-form
      ref="createModal"
      :visible="visible"
      :loading="confirmLoading"
      :model="mdl"
      @cancel="handleCancel"
      @ok="handleOk" /> -->
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { list, frozen, active, taskTileList } from '@/api/task'
import { taskExport } from '@/api/export'
const dict = [{ value: 0, text: '天' }, { value: 1, text: '次' }, { value: 2, text: '月' }, { value: 3, text: '年' }]
export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      data: [],
      queryParam: {},
      pageNum: 1,
      pageSize: 20,
      visible: false,
      mdl: null,
      columns: [
      {
          title: '任务标题',
          dataIndex: 'title'
        },
        {
          title: '省',
          dataIndex: 'province'
        },
        {
          title: '市',
          dataIndex: 'city'
        },
        {
          title: '区',
          dataIndex: 'area'
        },
        {
          title: '开始时间',
          dataIndex: 'beginDate'
        },
        {
          title: '到期时间',
          dataIndex: 'endDate'
        },
        {
          title: '联系电话',
          dataIndex: 'contactNumber'
        },
        {
          title: '内容描述',
          dataIndex: 'content'
        },
        {
          title: '任务报酬（元）',
          dataIndex: 'taskScore'
        },
        {
          title: '计酬方式',
          dataIndex: 'taskUnit',
          customRender: (val) => {
            const item = dict.find(i => i.value === val)
            return item && item.text
          }
        },
        {
          title: '其他要求',
          dataIndex: 'taskNote'
        },
        {
          title: '长期状态',
          dataIndex: 'validationLong',
          customRender: (val) => {
            return val == 0 ? '短期' : '长期'
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: 100,
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created () {
    // this.getTaskTileList()
  },
  methods: {
    handleSearch (e) {
      this.$refs.table.refresh()
    },
    async getTaskTileList() {
      const res = await taskTileList()
    },
    handleEdit (record) {
      this.visible = true
      this.mdl = { ...record }
    },
    handleReset () {
      this.queryParam = {}
      this.$refs.table.refresh()
    },
    loadData (params) {
      return list(Object.assign(params, this.queryParam)).then(res => {
        return res.data
      })
    },
    handleExport() {
      if (!this.$refs.table.localDataSource.length) {
        this.$message.warning('列表为空，不能导出')
        return
      }
      taskExport(this.queryParam)
    },
    handleAdd () {
      this.mdl = null
      this.$refs.createModal.startTime = ''
      this.$refs.createModal.endTime = ''
      this.$refs.createModal.fileList = []
      this.visible = true
    },
    handleCancel () {
      this.visible = false
      this.$refs.createModal.fileList = []
      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    handleStatus (row) {
      const { state, id } = row
      this.$confirm({
        title: `您确定要${state === 1 ? '冻结' : '激活'}该任务吗？`,
        onOk: () => {
          if (row.state === 1) {
            frozen([id]).then(() => {
              this.$message.success('冻结成功')
              this.$refs.table.refresh()
            })
          } else {
            active([id]).then(() => {
              this.$message.success('激活成功')
              this.$refs.table.refresh()
            })
          }
        }
      })
    }
  }
}
</script>
